package com.lins.msm.controller;

import com.alibaba.druid.util.StringUtils;
import com.lins.msm.bo.MsmService;
import com.lins.store.controller.BaseController;
import com.lins.common.util.JsonResult;
import com.lins.store.entity.ex.UserException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author linshuo
 * @Date 2022/11/17 14:59
 * 发送短信
 */

@RestController
@RequestMapping("msm")
public class MsmController extends BaseController {

    @Autowired
    private MsmService msmService;


    //发送手机验证码
    @GetMapping("send/{phone}/{yxq}")
    public JsonResult sendCode(@PathVariable String phone,@PathVariable String yxq) {
        if(StringUtils.isEmpty(phone)) throw new UserException("手机号为空！");
        JsonResult r = new JsonResult();
        switch (msmService.sendReady(phone, yxq)){
            case 0:
                r.setState(500);
                r.setMessage("发送失败，请联系管理员");
                break;
            case 1:
                r.setState(200);
                r.setMessage("发送成功");
                break;
            case 2:
                r.setState(502);
                r.setMessage("发送过于频繁，请1分钟后重试");
                break;
        }
        return r;
    }
}
